package com.shujia.city.dwd

import org.apache.spark.internal.Logging
import org.apache.spark.sql.{DataFrame, SaveMode, SparkSession}

/**
 * 房产信息明细表
 */
object DwdFcjNwrsSellbargainMskDay extends SparkTool {
  /**
   * 在run函数中写数据处理的逻辑
   * import spark.implicits._
   * import org.apache.spark.sql.functions._
   */
  override def run(spark: SparkSession, ds: String): Unit = {

    import spark.implicits._
    import org.apache.spark.sql.functions._

    //1、读取hive中ods的购房合同表
    val sell: DataFrame = spark
      .table("ods.ods_t_fcj_nwrs_sellbargain")
      .where($"ds" === ds)

    //2、处理数据，对数据脱敏
    val resultDF: DataFrame = sell.select(
      upper(md5(concat($"id", expr("'shujia'")))) as "id", //身份证号脱敏处理
      regexp_replace($"r_fwzl", "[A-Za-z0-9]", "*") as "r_fwzl",
      $"htydjzmj",
      $"tntjzmj",
      $"ftmj",
      $"time_tjba",
      $"htzj"
    )

    //3、保存数据
    saveToTable(spark, resultDF, "dwd.dwd_fcj_nwrs_sellbargain_msk_d", ds)

  }
}
